package com.dk.category.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.category.constants.CategoryConstants;
import com.dk.category.dao.CategoryDao;
import com.dk.category.dto.CategoryDTO;
import com.dk.category.entity.CategoryEntity;
import com.dk.category.service.CategoryService;
import com.ts.common.core.service.impl.CrudServiceImpl;
import com.ts.common.core.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author toString toString@qq.com
 * @since 1.0.0 2023-12-04
 */
@Service
public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, CategoryEntity, CategoryDTO> implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public QueryWrapper<CategoryEntity> getWrapper(Map<String, Object> params) {
        QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
        if (params != null) {
            String id = (String) params.get("id");
            wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        }
        return wrapper;
    }


    @Override
    public List<CategoryDTO> getHot(Integer count) {
        List<CategoryEntity> entityList = categoryDao.getHot(count);
        List<CategoryDTO> categoryDTOS = ConvertUtils.sourceToTarget(entityList, CategoryDTO.class);
        return categoryDTOS;
    }

}